package h_eekwan.service;

import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;

import java.net.ConnectException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import h_eekwan.interfaces.TestMyDataService;
import h_eekwan.module.TestMyDataVO;

public class TestMyDataDAO implements TestMyDataService{
	// JDBC 접속
	private static final String DRV = "oracle.jdbc.OracleDriver"; 
	private static final String URL = "jdbc:oracle:thin:@//localhost:1521/xe";
	private static final String USR = "scott";
	private static final String PWD = "TIGER";
	// SQL문 작성
	private static final String selectSQL = " SELECT ID, NAME FROM MY_DATA ";
	private static final String selectOneSQL = " SELECT * FROM MY_DATA WHERE ID = ? ";
	private static final String insertSQL = " INSERT INTO MY_DATA VALUES(MYDATA.nextval, ?, ?, ?, sysdata) ";
	private static final String updateSQL = " UPDATE MY_DATA SET NAME = ?, USERID= ?, SALARY = ? WHERE ID = ? ";
	private static final String deleteSQL = "DELETE FROM MY_DATA WHERE ID = ? ";
	@Override
	public String selectMyData() {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String result = "";
		
		try{
			Class.forName(DRV);
			conn = DriverManager.getConnection(URL, USR, PWD);
			ps = conn.prepareStatement(selectSQL);
			rs = ps.executeQuery();
				while(rs.next()){
					for(int i  =1; i<=5; ++i)
						result += rs.getString(i) + " ";
					result += "\n";
				}
			
		}catch(Exception ex ){
			ex.printStackTrace();
		}finally{
			if ( rs != null)
				try { rs.close(); } catch(Exception e){}
			if ( ps != null)
				try { ps.close(); } catch(Exception e){}
			if ( conn != null)
				try { conn.close(); } catch(Exception e){}
			
		}
		return result;
	}
	@Override
	public String selectMyData(String id) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public int insertMyData(TestMyDataVO v) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public int updateMyData(TestMyDataVO v) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public int deleteMyData(String id) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	
	
}
